#include <iostream>
using namespace std;

void Merge(int R[],int T[],int low,int mid,int high)
{
    int i=low,j=mid+1,k=low;
    while(j<=high&&i<=mid)
    {
        if(R[i]<=R[j])   T[k++]=R[i++];
        else  T[k++]=R[j++];
    }
    while(i<=mid) T[k++]=R[i++];
    while(j<=high) T[k++]=R[j++];
    for(i=0;i<=high;i++)
        R[i]=T[i];
}

void Merge_pass(int R[],int T[],int length,int n)
{
    int i;
    for(i=0;i<=n-2*length;i=2*length+i)
    {
        Merge(R,T,i,i+length-1,i+length*2-1);
    }
    if(i+length<n)  Merge(R,T,i,i+length-1,n-1);
     else
     for(int j=i;j<n;j++)
        T[j]=R[j];
}

void MSort(int R[],int T[],int n)
{
    int j=1,i;
    while(j<n)
    {
        Merge_pass(R,T,j,n);
         for(i=0;i<n;i++)
         cout << T[i]<<" ";
         cout<<"\n";
        j=j*2;
    }
}

int main()
{
    int i,n;
    cin>>n;
    int R[n],T[n];
    for(i=0;i<n;i++)
    cin>>R[i];
    MSort(R,T,n);
    return 0;
}
